#!/bin/sh

version=`git log --date=iso --pretty=format:"%cd @%H" -1`
if [ $? -ne 0 ]; then
    version="unknown version"
fi

compile=`date +"%F %T %z"`
if [ $? -ne 0 ]; then
    compile="unknown datetime"
fi

describe=`git describe --tags 2>/dev/null`
if [ $? -eq 0 ]; then
    version="${version} @${describe}"
fi

cat << EOF > proxy/internal/utils/version.go
package utils

const (
    Version = "$version"
    Compile = "$compile"
)
EOF

cat << EOF > stored/internal/utils/version.go
package utils

const (
    Version = "$version"
    Compile = "$compile"
)
EOF

cat << EOF > dashboard/internal/utils/version.go
package utils

const (
    Version = "$version"
    Compile = "$compile"
)
EOF